(function(){
    function Food(){
    this.color = 'red';//后期可以修改
    this.x = 0;
    this.y = 0;
    this.width = window.blockSize + 'px';
    this.height = window.blockSize + 'px';
} 
//生成随机的x,y值
    function randomPosition(){
        var n = Math.floor(Math.random()* window.mapSize);
        console.log(n);
        return n;
    }
    
    var foodElements = [];

    function removeElements(){
        for(var i = foodElements.length - 1; i >= 0; i--){
            window.map.removeChild(foodElements[i]);
            foodElements.splice(i,1);
        }
    }

Food.prototype.render =function(){
    removeElements();
    var div =document.createElement('div');
    foodElements.push(div);
    window.map.appendChild(div);
    this.x = randomPosition();
    this.y = randomPosition();
    with(div.style){
        width = this.width;
        height = this.height;
        background = this.color;
        position = 'absolute';
        left =this.x * window.blockSize + 'px';
        top =this.y * window.blockSize + 'px';
        borderRadius = '50%';
        
    }
}
window.Food = Food;

}());
